package ecmnext.agent;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * <p>Title: ECMNextAgent</p>
 * <p>Description: agent automatique pour ECMNext</p>
 * <p>Copyright: Copyright (c) 2011</p>
 * <p>Company: </p>
 * @author Xuewen YANG ET Antoine COUDERC
 * @version 0.1
 */

public class ECMAgentFrame extends JFrame {

  private static final long serialVersionUID = 4174169981939488216L;
  JPanel contentPane;
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu jMenuFile = new JMenu();
  JMenuItem jMenuFileExit = new JMenuItem();
  JMenu jMenuHelp = new JMenu();
  JMenuItem jMenuHelpAbout = new JMenuItem();
  JLabel statusBar = new JLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTextArea jTextArea1 = new JTextArea();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  Border border1;
  Border border2;

  //Construct the frame
  public ECMAgentFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    border1 = BorderFactory.createEmptyBorder();
    border2 = BorderFactory.createLineBorder(Color.black,1);
    contentPane.setLayout(gridBagLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Agent Settings");
    statusBar.setText(" ");
    jMenuFile.setText("File");
    jMenuFileExit.setText("Exit");
    jMenuFileExit.addActionListener(new ECMAgentFrame_jMenuFileExit_ActionAdapter(this));
    jMenuHelp.setText("Help");
    jMenuHelpAbout.setText("About");
    jMenuHelpAbout.addActionListener(new ECMAgentFrame_jMenuHelpAbout_ActionAdapter(this));
    jTextArea1.setEnabled(true);
    jTextArea1.setBorder(border1);
    jTextArea1.setEditable(false);
    jTextArea1.setMargin(new Insets(3, 3, 3, 3));
    jTextArea1.setText("");
    jScrollPane1.setBorder(border2);
    jMenuFile.add(jMenuFileExit);
    jMenuHelp.add(jMenuHelpAbout);
    jMenuBar1.add(jMenuFile);
    jMenuBar1.add(jMenuHelp);
    this.setJMenuBar(jMenuBar1);
    contentPane.add(statusBar,   new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    contentPane.add(jScrollPane1,   new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
    jScrollPane1.getViewport().add(jTextArea1, null);
  }

  //File | Exit action performed
  public void jMenuFileExit_actionPerformed(ActionEvent e) {
    System.exit(0);
  }

  //Help | About action performed
  public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
    ECMAgentFrame_AboutBox dlg = new ECMAgentFrame_AboutBox(this);
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = getSize();
    Point loc = getLocation();
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setModal(true);
    dlg.pack();
    dlg.show();
  }

  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      jMenuFileExit_actionPerformed(null);
    }
  }
}

class ECMAgentFrame_jMenuFileExit_ActionAdapter implements ActionListener {
  ECMAgentFrame adaptee;

  ECMAgentFrame_jMenuFileExit_ActionAdapter(ECMAgentFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jMenuFileExit_actionPerformed(e);
  }
}

class ECMAgentFrame_jMenuHelpAbout_ActionAdapter implements ActionListener {
  ECMAgentFrame adaptee;

  ECMAgentFrame_jMenuHelpAbout_ActionAdapter(ECMAgentFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jMenuHelpAbout_actionPerformed(e);
  }
}

